package com.jb.repair.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.jb.repair.R;
import com.jb.repair.model.DocModel;

import java.util.List;

/**
 * Created by gaobin on 2015/11/17.
 */
public class DocAdapter extends BaseAdapter {
    private Context context;
    private List<DocModel> mData;
    private LayoutInflater mInflater;

    public DocAdapter(Context context, List<DocModel> mData) {
        this.context = context;
        this.mData = mData;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        Holder holder;
        if (convertView == null) {
            view = mInflater.inflate(R.layout.item_doc, null);
            holder = new Holder();
            holder.tv_wjmc = (TextView) view.findViewById(R.id.tv_doc_wjmc);
            holder.tv_uname = (TextView) view.findViewById(R.id.tv_doc_uname);
            holder.tv_time = (TextView) view.findViewById(R.id.tv_doc_time);
            holder.tv_department = (TextView) view.findViewById(R.id.tv_doc_department);

            view.setTag(holder);

        } else {
            holder = (Holder) view.getTag();
        }
        DocModel model = mData.get(position);

        holder.tv_wjmc.setText(model.getDocName());
        holder.tv_uname.setText(model.getCreatPerson());
        holder.tv_time.setText(model.getDate());
        holder.tv_department.setText(model.getDepartment());

        return view;
    }

    private class Holder {
        private TextView tv_wjmc;
        private TextView tv_uname;
        private TextView tv_time;
        private TextView tv_department;

    }
}
